/**
 * 
 * 本类作用：获取零部件Link属性，即BOM结构属性
 * 
 * @author 魏文杰 
 * @Version 1.0
 * @Date 2013-10-08
 */

package ext.generic.erp.attributes;

import java.rmi.RemoteException;

import ext.com.iba.IBAUtil;
import ext.generic.erp.common.CommonPDMUtil;
import wt.method.RemoteAccess;
import wt.part.WTPart;
import wt.part.WTPartUsageLink;
import wt.util.WTException;

public class PartUsageLinkAttribute implements RemoteAccess{
	//父件编号
	public static final String PARENT_PART_NUMBER = "parentNumber" ;
	
	//父件视图
	public static final String PARENT_PART_VIEW = "parentView" ;
	
	//父件大版本
	public static final String PARENT_PART_MAJOR_VERSION= "parentMajorVersion" ;
	
	//父件完整版本
	public static final String PARENT_PART_VERSION = "parentVersion" ;
	
	// 子件编号
	public static final String CHILD_PART_NUMBER = "childNumber" ;
	
	public static final String LINE_NUMBER = "lineNumber" ;
	
	private static final String FIND_NUMBER = "findNumber" ;

	private static final String QUANTITY = "quantity" ;
	
	private static final String UNIT = "unit" ;
	
	private static final String TRACE_CODE = "traceCode" ;
	
	private static final String OCCURRENCE = "occurrence" ;
	
	/**
	 * 获取属性
	 * 
	 * @param usageLink
	 * @param attributeName
	 * @return
	 */
	protected static String getAttribute(WTPartUsageLink usageLink , String attributeName ) {
		String attributeValue = "" ;

		try{
			if( attributeName.equals( PARENT_PART_NUMBER ) ){

				attributeValue = CommonPDMUtil.getParentNumber( usageLink );
				
			}else if( attributeName.equals( PARENT_PART_VIEW ) ){

				attributeValue = CommonPDMUtil.getParentView( usageLink );
				
			}else if( attributeName.equals( PARENT_PART_MAJOR_VERSION ) ){

				attributeValue = CommonPDMUtil.getParentMajorVersion(usageLink) ;
				
			}else if( attributeName.equals( PARENT_PART_VERSION ) ){

				attributeValue = CommonPDMUtil.getParentVersion( usageLink );
				
			}else if( attributeName.equals( CHILD_PART_NUMBER ) ){

				attributeValue = CommonPDMUtil.getChildNumber( usageLink );
				
			}else if( attributeName.equals( FIND_NUMBER ) ){

				attributeValue = usageLink.getFindNumber() ;
				
			}else if ( attributeName.equals( LINE_NUMBER ) ){

				attributeValue = CommonPDMUtil.getLineNumber( usageLink );
				
			}else if ( attributeName.equals( QUANTITY ) ){
				
				attributeValue = CommonPDMUtil.getQuantityValue( usageLink );
				
			}else if ( attributeName.equals( UNIT ) ){
				
				attributeValue = CommonPDMUtil.getERPMappingUnit( usageLink );
				
			}else if ( attributeName.equals( TRACE_CODE ) ){
				
				attributeValue = CommonPDMUtil.getTraceCode(usageLink);
				
			}else if ( attributeName.equals( OCCURRENCE ) ){
				
				attributeValue = CommonPDMUtil.getOccurrence(usageLink);
				
			}else{
				attributeValue = (String) IBAUtil.getIBAValue( usageLink , attributeName);
			}
			
			//当结构的属性在WTPartUsageLink上取不到时，从WTPart上取。
			//此代码可能根据不同的业务需求，会导致BUG
			if( attributeValue == null || attributeValue.trim().equals("") ){
				WTPart parent = usageLink.getUsedBy() ;
				attributeValue = PartAttribute.getAttribute( parent , attributeName ) ;
			}
		}catch(WTException wte){
			wte.printStackTrace() ;
		} catch (RemoteException e) {
			e.printStackTrace();
		}finally{
			
		}
		
		return attributeValue ;
	}
}
